package com.pkutech.carcasher.content;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pkutech.carcasher.R;
import com.pkutech.carcasher.model.HmSelectFormalOrder;
import com.pkutech.carcasher.model.SelectFormalOrder;
import com.shizhefei.mvc.IDataAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by cyy on 2016/6/19.
 */
public class HmSelectFormalOrderAdapter extends BaseAdapter implements IDataAdapter<List<HmSelectFormalOrder>> {

    private List<HmSelectFormalOrder> selectFormalOrders = new ArrayList<HmSelectFormalOrder>();
    private LayoutInflater inflater;

    public HmSelectFormalOrderAdapter(Context context) {
        super();
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return selectFormalOrders.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = inflater.inflate(R.layout.select_detail_order_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        HmSelectFormalOrder selectFormalOrder = selectFormalOrders.get(position);
        holder.text1.setText(selectFormalOrder.getCarnum());
        holder.text2.setText(selectFormalOrder.getRoadid());
        holder.text3.setText(selectFormalOrder.getCreatedate());
        holder.carportText.setText("("+selectFormalOrder.getCarportid()+"车位"+")");

        convertView.setTag(R.string.stopper_item_id, selectFormalOrder);
        return convertView;
    }

    @Override
    public void notifyDataChanged(List<HmSelectFormalOrder> data, boolean isRefresh) {
        if (isRefresh) {
            selectFormalOrders.clear();
        }
        selectFormalOrders.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public List<HmSelectFormalOrder> getData() {
        return selectFormalOrders;
    }

    static class ViewHolder {
        @BindView(R.id.text1)
        TextView text1;
        @BindView(R.id.text2)
        TextView text2;
        @BindView(R.id.text3)
        TextView text3;
        @BindView(R.id.carportText)
        TextView carportText;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
